package com.dragon.permission_service.Controller;

import com.dragon.permission_service.Service.PermissionService;
import com.dragon.permission_service.annotation.AuthCheck;
import com.dragon.permission_service.constant.UserConstant;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


// 查询用户角色码（返回role_code）
    ;

    // 超管调用：升级用户为管理员
    ;

    // 超管调用：降级用户为普通角色
    ;

@RestController
@RequestMapping(path = "/user")
public class permissionController {
    @Resource
    private PermissionService permissionService;


    @GetMapping("/bind")
    public void bindDefaultRole(Long userId){
        permissionService.bindDefaultRole(userId);
    }

    //
    @GetMapping ("/get")
    public String getUserRoleCode(Long userId){
        String userRoleCode = permissionService.getUserRoleCode(userId);
        return userRoleCode;
    }

    //登陆生成JWT TOKEN
    @AuthCheck(mustRole = UserConstant.SUPER_ADMIN_ROLE)
    @PostMapping("/upgrade")
    public void upgradeToAdmin(Long userId){
        permissionService.upgradeToAdmin(userId);
    }
    @AuthCheck(mustRole = UserConstant.SUPER_ADMIN_ROLE)
    @PostMapping("/downgrade")
    public void downgradeToUser(Long userId){
        permissionService.downgradeToUser(userId);
    }

}
